package cn.ly.security.controller;

import cn.ly.security.entity.User;
import cn.ly.security.service.UserService;
import cn.ly.security.service.impl.UserServiceImpl;
import cn.ly.security.util.DataPojo;
import io.swagger.annotations.Api;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Map;

@RestController
@RequestMapping("/authority")
@Api(tags="登入注册/权限")
@CrossOrigin("*")
public class LoginAndRegist {
    @Autowired
    UserService userService;

    @PostMapping("login")
    public Map<String,Object> login(User user){
        Map<String, Object> login = userService.login(user.getUUsername(), user.getUPassword());
        return login;
    }
    @PutMapping("regist")
    public DataPojo regist(User user){
        User registcheck = userService.registcheck(user.getUUsername());
        boolean save=false;
        if (registcheck==null){
             save = userService.save(user);
        }
        ArrayList<Object> objects = new ArrayList<>();
        objects.add(save);
        return new DataPojo("200","无异常",objects);
    }
}
